package com.yn.xr.front.news.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yn.xr.common.constants.CommonDef;
import com.yn.xr.common.constants.CommonDef.SucceedOrFaultType;
import com.yn.xr.common.page.Page;
import com.yn.xr.front.base.constants.SystemConstants;
import com.yn.xr.front.news.service.NewsCommentService;
import com.yn.xr.middleware.news.rmi.NewsInfoRmiService;
import com.yn.xr.news.mode.NewsComment;
import com.yn.xr.news.mode.NewsCommentRevert;
import com.yn.xr.news.mode.NewsInfo;

@Service("newsCommentService")
public class NewsCommentServiceImpl implements NewsCommentService {

	private static final Logger logger = LoggerFactory .getLogger(NewsCommentServiceImpl.class);
	
	@Resource
	private NewsInfoRmiService newsInfoRmiService;
	
	@Override
	public Map<String, Object> addCommentOrRevert(String type, Long userId,
			Integer newsIdOrcommentId, String words, String accName, String ip)
			throws Exception {
		Map<String, Object> refData = new HashMap<String, Object>();
		try {
			NewsComment newsComment = new NewsComment(null, newsIdOrcommentId,
					userId.intValue(), words, new Date(), null, null,
					SucceedOrFaultType.succeed.getValue(),
					SucceedOrFaultType.succeed.getValue(),
					SucceedOrFaultType.fault.getValue(), (short) 0, null,
					accName, SystemConstants.platformId, null);
			newsInfoRmiService.addCommentOrRevert(newsComment);
			
			refData.put(CommonDef.resFlag, true);
			refData.put(CommonDef.resMsgCode,  "");
			refData.put(CommonDef.resMsg,  "");
			return refData;
		} catch (Exception e) {
			refData.put(CommonDef.resMsg,  e.toString());
			logger.error("【---调用新闻评论与回复接口异常:--】" + e.toString());
			throw e;
		}
	}

	@Override
	public Page<NewsComment> queryCommentPage(String hql ,Object[] queryParams , int pageNum, int pageSize ) throws Exception {
		return newsInfoRmiService.queryCommentPage(hql, queryParams, pageNum, pageSize);
	}

	@Override
	public List<NewsCommentRevert> queryCommentRevertList(Integer newsId,
			Integer commentId, Short status) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
